import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '@/layout'
import UserManageRouter from './modules/UserManage'
import RoleListRouter from './modules/RoleList'
import PermissionListRouter from './modules/PermissionList'
import ArticleRouter from './modules/Article'
import ArticleCreaterRouter from './modules/ArticleCreate'
import store from '@/store'
/**
 * 私有路由表
 */
export const privateRoutes = [
  // {
  //   path: '/user',
  //   component: layout,
  //   redirect: '/user/manage',
  //   meta: {
  //     title: 'user',
  //     icon: 'personnel'
  //   },
  //   children: [
  //     {
  //       path: '/user/manage',
  //       component: () => import('@/views/user-manage/index'),
  //       meta: {
  //         title: 'userManage',
  //         icon: 'personnel-manage'
  //       }
  //     },
  //     {
  //       path: '/user/role',
  //       component: () => import('@/views/role-list/index'),
  //       meta: {
  //         title: 'roleList',
  //         icon: 'role'
  //       }
  //     },
  //     {
  //       path: '/user/permission',
  //       component: () => import('@/views/permission-list/index'),
  //       meta: {
  //         title: 'permissionList',
  //         icon: 'permission'
  //       }
  //     },
  //     {
  //       path: '/user/info/:id',
  //       name: 'userInfo',
  //       component: () => import('@/views/user-info/index'),
  //       meta: {
  //         title: 'userInfo'
  //       }
  //     },
  //     {
  //       path: '/user/import',
  //       name: 'import',
  //       component: () => import('@/views/import/index'),
  //       meta: {
  //         title: 'excelImport'
  //       }
  //     }
  //   ]
  // },
  // {
  //   path: '/article',
  //   component: layout,
  //   redirect: '/article/ranking',
  //   meta: {
  //     title: 'article',
  //     icon: 'article'
  //   },
  //   children: [
  //     {
  //       path: '/article/ranking',
  //       component: () => import('@/views/article-ranking/index'),
  //       meta: {
  //         title: 'articleRanking',
  //         icon: 'article-ranking'
  //       }
  //     },
  //     {
  //       path: '/article/:id',
  //       component: () => import('@/views/article-detail/index'),
  //       meta: {
  //         title: 'articleDetail'
  //       }
  //     },
  //     {
  //       path: '/article/create',
  //       component: () => import('@/views/article-create/index'),
  //       meta: {
  //         title: 'articleCreate',
  //         icon: 'article-create'
  //       }
  //     },
  //     {
  //       path: '/article/editor/:id',
  //       component: () => import('@/views/article-create/index'),
  //       meta: {
  //         title: 'articleEditor'
  //       }
  //     }
  //   ]
  // }
  UserManageRouter,
  RoleListRouter,
  PermissionListRouter,
  ArticleRouter,
  ArticleCreaterRouter
]

/**
 * 公开路由表
 */
export const publicRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  {
    path: '/',
    // 注意：带有路径“/”的记录中的组件“默认”是一个不返回 Promise 的函数
    component: layout,
    redirect: '/profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('@/views/profile/index'),
        meta: {
          title: 'profile',
          icon: 'personnel'
        }
      },
      {
        path: '/chart',
        name: 'chart',
        component: () =>
          import(/* webpackChunkName: "chart" */ '@/views/chart/index'),
        meta: {
          title: 'chart',
          icon: 'chart'
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401')
      }
    ]
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes: [...publicRoutes]
})
/**
 * 初始化路由表
 */
export function resetRouter() {
  if (store.getters.userInfo?.permission?.menus) {
    const menus = store.getters.userInfo.permission.menus
    menus.forEach((menu) => {
      router.removeRoute(menu)
    })
  }
}

export default router
